import 'package:flutter/cupertino.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class IndexSlideBanner extends StatefulWidget {
  const IndexSlideBanner({Key key}) : super(key: key);

  @override
  _IndexSlideBannerState createState() => _IndexSlideBannerState();
}

class _IndexSlideBannerState extends State<IndexSlideBanner> {
  List<String> list = [
    'assets/images/index_rank_banner.png',
  ];

  //自定圆点分页指示器
  buildSwiperPagination() {
    // 分页指示器
    return SwiperPagination(
      //指示器显示的位置
        alignment: Alignment.bottomRight, // 位置 Alignment.bottomCenter 底部中间
        // 距离调整
        margin: const EdgeInsets.fromLTRB(0, 0, 16, 10),
        // 指示器构建
        builder: DotSwiperPaginationBuilder(
          // 点之间的间隔
          space: 2,
          // 没选中时的大小
          size: 7,
          // 选中时的大小
          activeSize: 7,
          // 没选中时的颜色
          color: Color(0xfff3f3f3),
          //选中时的颜色
          activeColor: Color(0xff0c0c0c),
        )
    );
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      height: 139,
      child: new Swiper(
        // 横向
        scrollDirection: Axis.horizontal,
        // 布局构建
        itemBuilder: (BuildContext context, int index) {
          return Padding(padding: EdgeInsets.all(6.0),
            child: Container(
              //设置背景图片
              decoration: new BoxDecoration(
                // color: Colors.grey,
                // border: new Border.all(width: 2.0, color: Colors.red),
                borderRadius: new BorderRadius.all(Radius.circular(10.0)),
                image: new DecorationImage(
                    image: new AssetImage(list[index]),
                    fit: BoxFit.cover
                ),
              ),
            ),
          );
        },
        //条目个数
        itemCount: list.length,
        // 自动翻页
        autoplay: true,
        // 分页指示
        pagination: buildSwiperPagination(),
        //点击事件
        onTap: (index) {
          print(" 点击 " + index.toString());
        },
        // 视窗比例
        viewportFraction: 1,
        // 布局方式
        //layout: SwiperLayout.STACK,
        // 用户进行操作时停止自动翻页
        autoplayDisableOnInteraction: true,
        //分页
        // 无线轮播
        loop: true,
        scale: 1, //
      ),
    );
  }
}
